<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者，助力中小企业发展 
+----------------------------------------------------------------------
| Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
+----------------------------------------------------------------------
| 沃德代驾系统并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
+----------------------------------------------------------------------
| 计价规则 开发者: 麦沃德科技-半夏  
+---------------------------------------------------------------------- -->

<template>
	<view class="container" v-if="loadEnd">
		<view class="container-header text-center">—— {{getCurrentCity()}} ——</view>
		<view class="container-main">
			<view class="main-column" v-if="rulesInfo.starting_price_list.length">
				<view class="column-title">起步价</view>
				<view class="column-content">
					<view class="text">实际计费以发单时间为准</view>
					<view class="text" v-for="(item, index) in rulesInfo.starting_price_list" :key="index">
						{{item.start_time}}-{{item.end_time}} {{item.price}}元/含{{item.kilometer}}公里
					</view>
				</view>
			</view>
			<view class="main-column" v-if="rulesInfo.mileage_fee">
				<view class="column-title">里程费</view>
				<view class="column-content">
					<view class="text">超出起步里程后计算</view>
					<view class="text">{{rulesInfo.mileage_fee.mileage_fee_start_time}}-{{rulesInfo.mileage_fee.mileage_fee_end_time}} {{rulesInfo.mileage_fee.mileage_price}}元/含1.0公里</view>
				</view>
			</view>
			<view class="main-column" v-if="rulesInfo.long_distance">
				<view class="column-title">远途费</view>
				<view class="column-content">
					<view class="text">{{rulesInfo.long_distance.long_distance_fee_start_time}}-{{rulesInfo.long_distance.long_distance_fee_end_time}}时段，总行驶里程超出一定距离后，加收远途费，{{rulesInfo.long_distance.capped_price}}元封顶。</view>
					<view class="text">超出{{rulesInfo.long_distance.exceeding_kilometers}}公里后，加收远途费{{rulesInfo.long_distance.long_distance_price}}元/1.0公里</view>
				</view>
			</view>
			<view class="main-column" v-if="rulesInfo.duration">
				<view class="column-title">等候费</view>
				<view class="column-content">
					<view class="text">司机到达后和订单进行中产生的总等候时长超出免费等候时长，收取等候费。免费等候时长{{rulesInfo.duration.free_waiting_time}}分钟，收费时长上限{{rulesInfo.duration.maximum_charging_duration}}分钟，等候时长不计入行驶时长。</view>
					<view class="text">{{rulesInfo.duration.duration_fee_start_time}}-{{rulesInfo.duration.duration_fee_end_time}} {{rulesInfo.duration.duration_price}}元/1分钟</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 加载完成
				loadEnd: false,
				// 计价规则
				rulesInfo: {},
				// 当前城市
				currentCity: "",
			}
		},
		onLoad(option) {
			this.currentCity = option.city
			uni.showLoading({
				title: "加载中"
			})
			this.getPricingRules(() => {
				uni.hideLoading()
				this.loadEnd = true
			})
		},
		methods: {
			// 获取当前城市
			getCurrentCity() {
				var str = this.currentCity
				if (typeof str !== 'string') {
					return str;
				}
				return str.replace(/\//g, "");
			},
			// 获取计价规则
			getPricingRules(fn) {
				this.$util.request("driver.order.pricingRules", {
					city: this.currentCity
				}).then(res => {
					if (fn) fn()
					if (res.code == 1) {
						this.rulesInfo = res.data
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}).catch(error => {
					console.error('获取计价规则 ', error)
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #fff;
	}

	.container {
		padding: 48rpx 32rpx;

		.container-header {
			color: #242629;
			font-size: 32rpx;
			font-weight: 600;
			line-height: 48rpx;
		}

		.container-main {
			margin-top: 48rpx;

			.main-column {
				.column-title {
					color: #242629;
					font-size: 32rpx;
					font-weight: 600;
					line-height: 48rpx;
				}

				.column-content {
					.text {
						color: #242629;
						font-size: 28rpx;
						font-weight: 400;
						line-height: 44rpx;
					}
				}
			}
		}
	}
</style>